package com.example.designpattern.responsibility_three.validator;

import cn.hutool.core.util.StrUtil;
import com.example.designpattern.responsibility_three.AbstractValidator;
import com.example.model.GoodsDTO;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 非空校验
 *
 * @author long
 * @date 2024/4/20 10:43
 */
@Service
public class NotNullValidator extends AbstractValidator {

    @Override
    public void doValidate(GoodsDTO dto) {
        if(Objects.isNull(dto.getGoodsId())){
            throw new RuntimeException("商品编码id不能为空");
        }

        if(StrUtil.isBlank(dto.getGoodsName())){
            throw new RuntimeException("商品名称不能为空");
        }

        if(Objects.isNull(dto.getPrice())){
            throw new RuntimeException("商品价格不能为空");
        }

        if(Objects.isNull(dto.getStockQty())){
            throw new RuntimeException("商品库存数量不能为空");
        }
    }

    @Override
    protected void preValidate(GoodsDTO dto) {
        logger.info("----------非空校验开始----------");
    }

    @Override
    protected void postValidate(GoodsDTO dto) {
        logger.info("----------非空校验结束----------");
    }

    @Override
    public int getPriority() {
        return 0;
    }
}
